package com.smart_campus.teg.controller;

import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.sys.domain.User;
import com.smart_campus.teg.common.TEGResultObj;
import com.smart_campus.teg.service.TegTalkService;
import com.smart_campus.teg.vo.TegTalkVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/talk")
public class TalkController {
    @Autowired
    private TegTalkService tegTalkService;

    /**
     * 查询出所有谈心记录
     */
    @RequestMapping("selAllTalk")
    public DataGridView selAllTalk(TegTalkVo tegTalkVo){
        return tegTalkService.selTalk(tegTalkVo);
    }

    @RequestMapping("addTalk")
    public TEGResultObj addTalk(TegTalkVo tegTalkVo){
        User user = tegTalkService.selstudent(tegTalkVo.getStudentName());
        if (user == null){
            return new TEGResultObj(-1,"不存在此学生，添加失败");
        }
        tegTalkVo.setTalkTime(new Date());
        tegTalkService.insert(tegTalkVo);
        return new TEGResultObj(200,"添加成功");
    }

    @RequestMapping("removeTalk")
    public TEGResultObj removeTalk(int id[]){
        try {
            for (int i:id){
                tegTalkService.deleteByPrimaryKey(i);
            }
            return new TEGResultObj(200,"删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return new TEGResultObj(-1,"删除失败");
        }
    }

}
